﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CMWVS.Core;
using bleissem.CMWVS_Plugin.VS2010.Commands;
using System.ComponentModel.Design;
using Microsoft.VisualStudio.Shell.Interop;
using System.Globalization;
using CMWVS.Core.Mono;
using CMWVS.Core.Commands;
using EnvDTE80;
using System.Diagnostics;
using bleissem.CMWVS_Plugin.VS2010.UI;

namespace bleissem.CMWVS_Plugin_VS2010.Commands
{
    public class BuildCommand : BaseCommand
    {

        public BuildCommand():base(new CommandID(GuidList.GuidCMWVS_Plugin_Build, (int)PkgCmdIDList.IDCMWV_Plugin_Build))
        {
            
        }

        internal override void Initialize(MainViewModel mvm, Resolver resolver)
        {
            base.Initialize(mvm, resolver);

            this.Enabled = base.Resolver.Get<MonoConfig>().IsInstalled;
      }

        protected override void Execute()
        {
            var compile = base.m_MainViewModel.Compile;
            if (compile.CanExecute())
            {
                DTE2 dte2 = base.Resolver.Get<DTE2>();
                EnvDTE.Solution solution = dte2.Solution;

                if (null == solution)
                {
                    return;
                }

                ToOutputWindow outputWindow = new ToOutputWindow(base.Resolver);
                outputWindow.Clear();

                using(TraceListener traceListener = new AddInTraceListener((string message)=>
                    {
                        outputWindow.OutPut(message);
                    }))
                    {
                    
                    CompileCommandParamater compileParams;
                    BuildCompileParameters.Build(solution, traceListener, out compileParams);
                    compile.Execute(compileParams);
                    var result = compile.Result;
                }

            }                   
        }
    }
}
